package com.classba.udf;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class IPTranform extends UDF {
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();

    public Text evaluate(Text ip) {


        HttpGet httpGet = new HttpGet("http://www.baidu.com");

        CloseableHttpResponse response = null;
        try {
            response = httpClient.execute(httpGet);
        } catch (IOException e) {
            e.printStackTrace();
        }

        HttpEntity entity = response.getEntity();

        String s = null;
        try {
            s = EntityUtils.toString(entity);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return new Text(s);
    }

    public static void main(String[] args) {


        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        HttpGet httpGet = new HttpGet("http://www.baidu.com");

        CloseableHttpResponse response = null;
        try {
            response = httpClient.execute(httpGet);
        } catch (IOException e) {
            e.printStackTrace();
        }

        HttpEntity entity = response.getEntity();

        String s = null;
        try {
            s = EntityUtils.toString(entity);
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println(s);


    }
}